package com.srwl.mytx.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.srwl.mytx.utils.DateUtils;
import com.srwl.mytx.Constant;
import com.srwl.mytx.domain.CoinTransfer;
import com.srwl.mytx.parse.UserProfileManager;
import com.srwl.mytx.utils.Utils;
import com.srwl.mytx.R;

/**
 * 聊天页面 金币转账 ，原理类似 发红包，只是没有接收的一个过程，而是直接到账
 */
public class CoinTransferDetailActivity extends BaseActivity {

    public static void startActivity(Context context, CoinTransfer transfer) {
        context.startActivity(new Intent(context, CoinTransferDetailActivity.class).putExtra(Constant.EXTRA_TRANSFER_INFO, transfer));
    }

    private ImageView iv_transferIcon;
    private TextView tv_transfergreet, tv_transferAdd, tv_transferAmount, tv_transferSendTime, tv_saveInAliPay;

    private CoinTransfer transfer;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.rp_activity_transfer_detail);
        initViewsAndEvents();
    }

    protected void initViewsAndEvents() {
        transfer = getIntent().getParcelableExtra(Constant.EXTRA_TRANSFER_INFO);
        iv_transferIcon = findViewById(R.id.iv_transfer_status_icon);
        tv_transfergreet = findViewById(R.id.tv_transfer_greet);
        tv_transferAdd = findViewById(R.id.tv_transfer_add);
        tv_saveInAliPay = findViewById(R.id.tv_save_in_alipay);
        tv_transferAmount = findViewById(R.id.tv_transfer_amount);
        tv_transferSendTime = findViewById(R.id.tv_transfer_send_time);
        findViewById(R.id.tv_transfer_record).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(CoinTransferDetailActivity.this, TransferRecordActivity.class));
            }
        });
        showCoinTransfer();
    }

    private void showCoinTransfer() {
        tv_transferAmount.setText(Utils.moneyFormat(transfer.getAmount()));
        tv_transferSendTime.setText(DateUtils.getTimestampString(transfer.getCreated()));
        String loginUserID = UserProfileManager.getInstance().getLoginUserInfo().getuId();
        //判断自己是转账发起方，还是接收方
        if (TextUtils.equals(transfer.gettId(), loginUserID)) {
            tv_saveInAliPay.setText(getString(R.string.money_save_in_wallet));
        } else {
            tv_transferAdd.setText(R.string.transfer_money_reduce);
            tv_saveInAliPay.setText("对方已经收到该笔转账");
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


}
